package com.meituan.service.impl;

import com.meituan.dao.PermissionRepository;
import com.meituan.pojo.entity.Permission;
import com.meituan.pojo.req.PermissionReq;
import com.meituan.pojo.resp.BaseResp;
import com.meituan.service.PermissionService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    PermissionRepository permissionRepository;

    @Override
    public BaseResp findAll() {
        List<Permission> all = permissionRepository.findAll();
        return new BaseResp(1,"success",all);
    }

    @Override
    public BaseResp deleteById(Integer pid) {
        permissionRepository.deleteById(pid);
        return new BaseResp().SUCCESS();
    }

    @Override
    public BaseResp saveOrUpdate(PermissionReq permissionReq) {
        Permission permission = new Permission();
        BeanUtils.copyProperties(permissionReq,permission);
        permissionRepository.saveAndFlush(permission);
        return new BaseResp().SUCCESS();
    }
}
